let config = {
  url: "",
  data: {},
  method: "post"
}
function request(a) {
  config = Object.assign(config, a)
  //获取token信息
  var token = wx.getStorageSync('token');
  if (token) {
    config.data["token"] = token
  }
  config.data['from'] = "sp";

  return new Promise(function (resolve, reject) {
    wx.request({
      url: config.url,
      data: config.data,
      method: config.method,
      header: {
        'Content-Type': 'application/json'
      },
      success: function (res) {
        console.log(res.data.code)
        if (res.data.code == 900) {
          wx.removeStorageSync("token")
          wx.removeStorageSync("userInfo")
          wx.reLaunch({
            url: '/pages/login/login',
          })
        } else if (res.statusCode == 200) {
          resolve(res.data);
        } else {
          reject(res)
        }

      },
      fail: function (err) {
        reject(err)
        console.log("failed" + err)
      }
    })
  });
}
module.exports = {
  request
}